// hw_gpio_hal.c
#include "hw_gpio_hal.h"
#include "xil_printf.h"

XGpioPs GpioPs;

int HAL_GPIO_Init(void)
{
    int Status;
    XGpioPs_Config *ConfigPtr;

    ConfigPtr = XGpioPs_LookupConfig(GPIO_DEVICE_ID);
    if (NULL == ConfigPtr) {
        xil_printf("HAL_GPIO_Init: XGpioPs_LookupConfig FAILED! Device ID: %u\r\n", (unsigned int)GPIO_DEVICE_ID);
        return XST_FAILURE;
    }

    Status = XGpioPs_CfgInitialize(&GpioPs, ConfigPtr, ConfigPtr->BaseAddr);
    if (Status != XST_SUCCESS) {
        xil_printf("HAL_GPIO_Init: XGpioPs_CfgInitialize FAILED! Status: %d\r\n", Status);
        return XST_FAILURE;
    }
    xil_printf("HAL_GPIO_Init: GPIO Driver Initialized (ID: %u).\r\n", (unsigned int)GPIO_DEVICE_ID);
    return XST_SUCCESS;
}

void HAL_GPIO_SetDirection(u32 pin, u32 direction)
{
    XGpioPs_SetDirectionPin(&GpioPs, pin, direction);
}

void HAL_GPIO_SetOutputEnable(u32 pin, u32 enable)
{
    XGpioPs_SetOutputEnablePin(&GpioPs, pin, enable);
}

void HAL_GPIO_WritePin(u32 pin, u32 value)
{
    XGpioPs_WritePin(&GpioPs, pin, value);
}

u32 HAL_GPIO_ReadPin(u32 pin)
{
    return XGpioPs_ReadPin(&GpioPs, pin);
}
